package com.ruoyi.datastatistics.service.impl;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.datastatistics.domain.RealtimegatherdataXb;
import com.ruoyi.datastatistics.mapper.RealtimegatherdataXbMapper;
import com.ruoyi.datastatistics.service.IRealtimegatherdataXbService;
import com.ruoyi.datastatistics.vo.XbDatabase;
import com.ruoyi.datastatistics.vo.XbDatabaseVO;
import com.ruoyi.datastatistics.wxentity.WXRealtimegatherdataXb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * 实时数据采集（小）Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-07
 */
@Service
public class RealtimegatherdataXbServiceImpl implements IRealtimegatherdataXbService
{
    @Autowired
    private RealtimegatherdataXbMapper realtimegatherdataXbMapper;

    /**
     *  查询户表基础数据和实时数据
     *
     * @param req  req
     * @return 查询户表基础数据和实时数据
     */
    @Override
    public List<XbDatabase> basedataXb(XbDatabaseVO req){
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if(user != null){
            if(!Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_ADMIN)) {
                Long userId = user.getUserId();
                req.setSysUserId(userId);
            }
            if(Objects.equals(user.getSystemFlag(), Constants.SYS_FLAG_NORMAL_USER)){
                req.setTenantId(user.getTenantId());
            }
        }
        return realtimegatherdataXbMapper.basedataXb(req);
    }

    /**
     * 查询实时数据采集（小）
     *
     * @param TerminalID 实时数据采集（小）主键
     * @return 实时数据采集（小）
     */
    @Override
    public RealtimegatherdataXb selectRealtimegatherdataXbByTerminalID(String TerminalID)
    {
        return realtimegatherdataXbMapper.selectRealtimegatherdataXbByTerminalID(TerminalID);
    }

    /**
     * 查询实时数据采集（小）列表
     *
     * @param realtimegatherdataXb 实时数据采集（小）
     * @return 实时数据采集（小）
     */
    @Override
    public List<RealtimegatherdataXb> selectRealtimegatherdataXbList(RealtimegatherdataXb realtimegatherdataXb)
    {
        return realtimegatherdataXbMapper.selectRealtimegatherdataXbList(realtimegatherdataXb);
    }

    /**
     * 新增实时数据采集（小）
     *
     * @param realtimegatherdataXb 实时数据采集（小）
     * @return 结果
     */
    @Override
    public int insertRealtimegatherdataXb(RealtimegatherdataXb realtimegatherdataXb)
    {
        return realtimegatherdataXbMapper.insertRealtimegatherdataXb(realtimegatherdataXb);
    }

    /**
     * 批量新增
     * @param list
     */
    @Override
    public void batchinsertRealtimegatherdataXb(List<RealtimegatherdataXb> list)
    {
        realtimegatherdataXbMapper.batchinsertRealtimegatherdataXb(list);
    }
    /**
     * 修改实时数据采集（小）
     *
     * @param realtimegatherdataXb 实时数据采集（小）
     * @return 结果
     */
    @Override
    public int updateRealtimegatherdataXb(RealtimegatherdataXb realtimegatherdataXb)
    {
        return realtimegatherdataXbMapper.updateRealtimegatherdataXb(realtimegatherdataXb);
    }

    /**
     * 批量删除实时数据采集（小）
     *
     * @param TerminalIDs 需要删除的实时数据采集（小）主键
     * @return 结果
     */
    @Override
    public int deleteRealtimegatherdataXbByTerminalIDs(String[] TerminalIDs)
    {
        return realtimegatherdataXbMapper.deleteRealtimegatherdataXbByTerminalIDs(TerminalIDs);
    }

    /**
     * 删除实时数据采集（小）信息
     *
     * @param TerminalID 实时数据采集（小）主键
     * @return 结果
     */
    @Override
    public int deleteRealtimegatherdataXbByTerminalID(String TerminalID)
    {
        return realtimegatherdataXbMapper.deleteRealtimegatherdataXbByTerminalID(TerminalID);
    }

    @Override
    public List<RealtimegatherdataXb> selectRealtimegatherdataXbList2(RealtimegatherdataXb realtimegatherdataXb) {
        return realtimegatherdataXbMapper.selectRealtimegatherdataXbList2(realtimegatherdataXb);
    }

    @Override
    public List<RealtimegatherdataXb> selectList(RealtimegatherdataXb realtimegatherdataXb) {
        return realtimegatherdataXbMapper.selectList(realtimegatherdataXb);
    }

    @Override
    public List<WXRealtimegatherdataXb> selectWXRealtimegatherdataXbList(String terminalId, String startTime, String endTime) {
        return realtimegatherdataXbMapper.selectWXRealtimegatherdataXbList(terminalId,startTime,endTime);
    }
}
